using AutoMapper;
using System.Linq;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;
using System.Collections.Generic;

namespace Pay.Service.AutoMapper {
	public class OrderMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public OrderMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
			_cfg.CreateMap<order_dto, Data.Order>()
				.ForMember(dest => dest.OrderNo, src => src.MapFrom(c => c.order_no))
				.ForMember(dest => dest.MerchantId, src => src.MapFrom(c => c.merchant_id))
				.ForMember(dest => dest.OrderTime, src => src.MapFrom(c => c.order_time.ToUnix()))
				.ForMember(dest => dest.FinishTime, src => src.MapFrom(c => c.finish_time.ToUnix()))
				.ForMember(dest => dest.BuyId, src => src.MapFrom(c => c.buy_id))
                .ForMember(dest => dest.DistributionId, src => src.MapFrom(c => c.distribution_id))
                .ForMember(dest => dest.ShopId, src => src.MapFrom(c => c.shop_id))
                .ForMember(dest => dest.Remark, src => src.MapFrom(c => c.remark))
                .ForMember(dest => dest.MerchantRemark, src => src.MapFrom(c => c.merchant_remark))
                .ForMember(dest => dest.OrderAmount, src => src.MapFrom(c => c.order_amount))
				.ForMember(dest => dest.DiscountName, src => src.MapFrom(c => c.discount_name))
				.ForMember(dest => dest.IntegralDiscount, src => src.MapFrom(c => c.integral_discount))
				.ForMember(dest => dest.PayAmount, src => src.MapFrom(c => c.pay_amount))
                .ForMember(dest => dest.PostFee, src => src.MapFrom(c => c.post_fee))
                .ForMember(dest => dest.FeeAmount, src => src.MapFrom(c => c.fee_amount))
				.ForMember(dest => dest.Points, src => src.MapFrom(c => c.points))
				.ForMember(dest => dest.DisAmount, src => src.MapFrom(c => c.disAmount))
				.ForMember(dest => dest.OrderItems, src => src.MapFrom(c => c.order_items))
				.ForMember(dest => dest.ShippingType, src => src.MapFrom(c => c.shipping_type))
                .ForMember(dest => dest.PayInfo, src => src.MapFrom(c => c.pay_info))
                .ForMember(dest => dest.SinoFee, src => src.MapFrom(c => c.sino_fee))
                .ForMember(dest => dest.OrderType, src => src.MapFrom(c => c.order_type))
                .ForMember(dest => dest.IsBuyDel, src => src.MapFrom(c => c.is_buy_del))
                .ForMember(dest => dest.IsSellDel, src => src.MapFrom(c => c.is_seller_del))
                .ForMember(dest => dest.OrderSettle, src => src.MapFrom(c => c.order_settle_status))
                .ForMember(dest => dest.Binds, src => src.MapFrom(c => c.binds.ToJson()))
				.ForMember(dest => dest.Buyer, src => src.Ignore())
				.ForMember(dest => dest.Merchant, src => src.Ignore())
                .ForMember(dest => dest.RedDrill, src => src.MapFrom(c => c.red_drill))
                .ForMember(dest => dest.RedDrillReceiverId, src => src.MapFrom(c => c.red_drill_receiver_id))
                .ForMember(dest => dest.PushStatus, src => src.MapFrom(c => c.push_status))
                .ForMember(dest => dest.PushFailMsg, src => src.MapFrom(c => c.push_fail_msg));
			_cfg.CreateMap<Data.Order, order_dto>()
				.ForMember(dest => dest.order_no, src => src.MapFrom(c => c.OrderNo))
				.ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
                .ForMember(dest => dest.distribution_id, src => src.MapFrom(c => c.DistributionId))
                .ForMember(dest => dest.shop_id, src => src.MapFrom(c => c.ShopId))
                .ForMember(dest => dest.order_time, src => src.MapFrom(c => c.OrderTime.ToDateTime()))
				.ForMember(dest => dest.finish_time, src => src.MapFrom(c => c.FinishTime.ToDateTime()))
				.ForMember(dest => dest.buy_id, src => src.MapFrom(c => c.BuyId))
                .ForMember(dest => dest.remark, src => src.MapFrom(c => c.Remark))
                .ForMember(dest => dest.merchant_remark, src => src.MapFrom(c => c.MerchantRemark))
                .ForMember(dest => dest.order_amount, src => src.MapFrom(c => c.OrderAmount))
				.ForMember(dest => dest.disAmount, src => src.MapFrom(c => c.DisAmount))
				.ForMember(dest => dest.points, src => src.MapFrom(c => c.Points))
                .ForMember(dest => dest.sino_fee, src => src.MapFrom(c => c.SinoFee))
                .ForMember(dest => dest.discount_name, src => src.MapFrom(c => c.DiscountName))
				.ForMember(dest => dest.discount_amount, src => src.MapFrom(c => c.DiscountAmount))
				.ForMember(dest => dest.integral_discount, src => src.MapFrom(c => c.IntegralDiscount))
				.ForMember(dest => dest.pay_amount, src => src.MapFrom(c => c.PayAmount))
				.ForMember(dest => dest.fee_amount, src => src.MapFrom(c => c.FeeAmount))
				.ForMember(dest => dest.shipping_type, src => src.MapFrom(c => c.ShippingType))
				.ForMember(dest => dest.order_items, src => src.MapFrom(c => c.OrderItems))
				.ForMember(dest => dest.pay_info, src => src.MapFrom(c => c.PayInfo))
				.ForMember(dest => dest.merchant, src => src.MapFrom(c => c.Merchant))
				.ForMember(dest => dest.buyer, src => src.MapFrom(c => c.Buyer))
				.ForMember(dest => dest.shipping, src => src.MapFrom(c => c.Shipping))
                .ForMember(dest => dest.order_type, src => src.MapFrom(c => c.OrderType))
                .ForMember(dest => dest.is_buy_del, src => src.MapFrom(c => c.IsBuyDel))
                .ForMember(dest => dest.is_seller_del, src => src.MapFrom(c => c.IsSellDel))
                .ForMember(dest => dest.order_settle_status, src => src.MapFrom(c => c.OrderSettle))
                .ForMember(dest => dest.post_fee, src => src.MapFrom(c => c.PostFee))
                .ForMember(dest => dest.binds, src => src.MapFrom(c => c.Binds.ToObject<List<bind_merchant_item>>()))
                .ForMember(dest => dest.red_drill, src => src.MapFrom(c => c.RedDrill))
                .ForMember(dest => dest.red_drill_receiver_id, src => src.MapFrom(c => c.RedDrillReceiverId))
                .ForMember(dest => dest.push_fail_msg, src => src.MapFrom(c => c.PushFailMsg))
                .ForMember(dest => dest.push_status, src => src.MapFrom(c => c.PushStatus));
		}
	}

    public class OrderRefundMapper : IStartupDto {
        private IMapperConfigurationExpression _cfg;
        public OrderRefundMapper(IMapperConfigurationExpression cfg) {
            _cfg = cfg;
        }
        public void Execute() {
            Create();
        }
        protected virtual void Create() {
            _cfg.CreateMap<order_refund_dto, Data.OrderRefund>()
                .ForMember(dest => dest.MerchantId, src => src.MapFrom(c => c.merchant_id))
                .ForMember(dest => dest.OrderRefundNo, src => src.MapFrom(c => c.order_refund_no))
                .ForMember(dest => dest.Status, src => src.MapFrom(c => c.status))
                .ForMember(dest => dest.Type, src => src.MapFrom(c => c.type))
                .ForMember(dest => dest.CreateTime, src => src.MapFrom(c => c.create_time.ToUnix()))
                .ForMember(dest => dest.HandleTime, src => src.MapFrom(c => c.handle_time.ToUnix()))
                .ForMember(dest => dest.Remark, src => src.MapFrom(c => c.remark))
                .ForMember(dest => dest.Amount, src => src.MapFrom(c => c.amount))
                .ForMember(dest => dest.OrderId, src => src.MapFrom(c => c.order_id));

            _cfg.CreateMap<Data.OrderRefund, order_refund_dto>()
                .ForMember(dest => dest.order_refund_no, src => src.MapFrom(c => c.OrderRefundNo))
                .ForMember(dest => dest.handle_time, src => src.MapFrom(c => c.HandleTime.ToDateTime()));
        }
    }
}
